define(function () {    
    var ec=require('echarts');
    require('echarts/chart/pie'); 
    require('echarts/chart/funnel');

    
    var option_day = {
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient : 'vertical',
            x : 'left',
            data:[]
        },
        toolbox: {
            show : true,
             orient: 'vertical',
            feature : {
                mark : {show: false},
                dataView : {show: false, readOnly: false},
                magicType : {
                    show: true, 
                    type: ['pie', 'funnel']
                },
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        calculable : false,
        series : [
            {
                name:'',
                type:'pie',
                selectedMode: 'single',
                radius : [0, '70%'],
                // for funnel
                x: '20%',
                width: '40%',
                funnelAlign: 'right',
                max: 1000000,
                itemStyle : {
                    normal : {
                        label : {
                            show : true,
                            position:'outer'
                        },
                        labelLine : {
                            show : true
                        }
                    },
                    emphasis : {
                        label : {
                            show : true,
                            textStyle : {
                                fontSize : '13',
                                fontWeight : 'bold'
                            }
                        }
                    }
                },
                data:[]
            }
            ]
    };
    var zrUtil = require('zrender/tool/util');
    var sourcePie_age = ec.init(document.getElementById('resume_pie_age'));
    var sourcePie_education = ec.init(document.getElementById('resume_pie_education'));
    var sourcePie_work_years = ec.init(document.getElementById('resume_pie_work_years'));
    var sourcePie_salary_name = ec.init(document.getElementById('resume_pie_salary_name'));
    var option_age=zrUtil.clone(option_day);
    option_age.series[0].name="年龄";
    var option_education=zrUtil.clone(option_day);
    option_education.series[0].name="学历";
    var option_work_years=zrUtil.clone(option_day);
    option_work_years.series[0].name="工作年限";
    var option_salary_name=zrUtil.clone(option_day);
    option_salary_name.series[0].name="期望薪资";

    // var ecConfig = require('echarts/config');

    var optionMap={"age":[sourcePie_age,option_age] , "education": [sourcePie_education,option_education] ,"work_years": [sourcePie_work_years,option_work_years] ,"salary_name": [sourcePie_salary_name,option_salary_name] };

    function resetOption(echarts, option, initalData){
        option.legend.data = initalData.nameList;
        option.series[0].data = initalData.data;
 
        option.series[0].max = initalData.max;                

        echarts.setOption(option,true);
        echarts.hideLoading();
    }


    /**
     * 根据指标显示日数据
     * @param index
     */
    function show(businessName){
        var industry = $('#index_crowd_industry').val();
        var beginDate = $('#beginDate_crowd').val();
        var endDate = $('#endDate_crowd').val();

        $.each(optionMap,function(name,obj){
            var charts = obj[0];
            var option = obj[1];
            charts.showLoading({
                text: '正在努力的读取数据中...'
            });
            $.ajax({
                url: '/dashboard/info/ajax/resumeCrowd',
                type: 'post',
                async: true,
                data:{"industry": industry,"indexType":name,"beginDate":beginDate,"endDate":endDate},
                dataType: 'json',
                success: function(data, textStatus) {
                    resetOption(charts,option,data);
                },
                error : function() {
                    charts.hideLoading();
                }
            });
        });


    }

    // var zrnumber = require('echarts/util/number');



    //时间选择事件
    $('#beginDate_crowd').datepicker(datepicker_op);
    $('#endDate_crowd').datepicker(datepicker_op);
    $('#beginDate_crowd').datepicker().on('changeDate', function (e) {
        $('#endDate_crowd').datepicker('setStartDate', e.date);
    });

    $('#endDate_crowd').datepicker().on ('changeDate', function (e) {
        $('#beginDate_crowd').datepicker('setEndDate', e.date);
    });

    var EC={
        resize:function(){sourcePie.resize();},
        'show':show
    };

    //绑定刷新
    $("#refresh_crowd_btn").click(function(){
        EC.show(businessName);
    });

    return EC;
});